package com.squirrel.michale;

/**
 * @author guanhao 观浩
 * @version 1.0.0.0
 * @createTime 2023/2/24 8:16 PM
 * @company Michale Squirrel
 * @link
 * @description
 */
public class LeetCode0397 {

    public int integerReplacement(int n) {
        long m = n;
        int opCount = 0;
        while (m != 1) {
            if (m % 2 == 1) {
                long temp = m - 1;
                if (temp / 2 % 2 == 1 && temp / 2 != 1) {
                    m += 1;
                } else {
                    m = temp;
                }
            } else {
                m = m/2;
            }
            opCount++;
        }
        return opCount;
    }
}
